package example.com.zcq.mymj.fragment;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import example.com.zcq.mymj.R;
import example.com.zcq.mymj.activity.ContentActivity;
import example.com.zcq.mymj.activity.ExitActivity;
import example.com.zcq.mymj.activity.FeedbackActivity;
import example.com.zcq.mymj.activity.LoginActivity;
import example.com.zcq.mymj.util.PreferenceUtils;

/**
 * @author zcq
 * @package example.com.zcq.mymj.fragment
 * @fileName MyMj
 * @description: 这个类的描述
 * @org 融信通达科技有限公司
 * @email @163.com
 * @date 2018/11/22  19:59
 */
public class Fragment4 extends Fragment implements View.OnClickListener {

    private View view;
    private ImageView mIvSetting;
    private ImageView mIvNotLogin;
    /**
     * 马上登录
     */
    private Button mBtnLoginNow;
    private RelativeLayout mRlNotLogin;
    /**
     * 帮助中心
     */
    private TextView mTvHelpCenter;
    /**
     * 关于我们
     */
    private TextView mTvAboutUs;
    /**
     * 联系我们
     */
    private TextView mTvContactUs;
    /**
     * 意见反馈
     */
    private TextView mTvSuggestFeedback1;
    /**
     * 清除本地缓存
     */
    private TextView mTvClearCache;
    /**
     * 20.0M
     */
    private TextView mTvCacheSize;
    /**
     * 版本更新
     */
    private TextView mTvCheckUpdate;
    /**
     * 当前2018.02.07
     */
    private TextView mTvVersionName;
    private Intent intent;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fg4, container, false);
        initView(view);
        mTvCacheSize.setText("0.3M");
        intent = new Intent(getActivity(), ContentActivity.class);
        intent.putExtra("content", "邮箱：564663096@qq.com");
        return view;
    }

    private void initView(View view) {
        mIvSetting = (ImageView) view.findViewById(R.id.iv_setting);
        mIvNotLogin = (ImageView) view.findViewById(R.id.iv_not_login);
        mBtnLoginNow = (Button) view.findViewById(R.id.btn_login_now);
        mRlNotLogin = (RelativeLayout) view.findViewById(R.id.rl_not_login);
        mTvHelpCenter = (TextView) view.findViewById(R.id.tv_help_center);
        mTvAboutUs = (TextView) view.findViewById(R.id.tv_about_us);
        mTvContactUs = (TextView) view.findViewById(R.id.tv_contact_us);
        mTvSuggestFeedback1 = (TextView) view.findViewById(R.id.tv_suggest_feedback1);
        mTvClearCache = (TextView) view.findViewById(R.id.tv_clear_cache);
        mTvCacheSize = (TextView) view.findViewById(R.id.tv_cache_size);
        mTvCheckUpdate = (TextView) view.findViewById(R.id.tv_check_update);
        mTvVersionName = (TextView) view.findViewById(R.id.tv_versionName);
        mBtnLoginNow.setOnClickListener(this);
        mTvHelpCenter.setOnClickListener(this);
        mTvAboutUs.setOnClickListener(this);
        mTvContactUs.setOnClickListener(this);
        mTvSuggestFeedback1.setOnClickListener(this);
        mTvClearCache.setOnClickListener(this);
        mTvCacheSize.setOnClickListener(this);
        mTvCheckUpdate.setOnClickListener(this);
        mTvVersionName.setOnClickListener(this);
        mIvSetting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(), ExitActivity.class));

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.btn_login_now:
                startActivity(new Intent(getActivity(), LoginActivity.class));
                break;
            case R.id.iv_setting:
                startActivity(new Intent(getActivity(), ExitActivity.class));

                break;
            case R.id.tv_help_center:
                startActivity(intent.putExtra("title", "帮助中心"));
                break;
            case R.id.tv_about_us:
                startActivity(intent.putExtra("title", "关于我们"));
                break;
            case R.id.tv_contact_us:
                startActivity(intent.putExtra("title", "联系我们"));
                break;
            case R.id.tv_suggest_feedback1:
                startActivity(new Intent(getActivity(), FeedbackActivity.class));
                break;
            case R.id.tv_clear_cache:
                mTvCacheSize.setText("0.0M");
                Toast.makeText(getActivity(), "清除成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tv_cache_size:
                mTvCacheSize.setText("0.0M");
                Toast.makeText(getActivity(), "清除成功", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tv_check_update:
                Toast.makeText(getActivity(), "已经是最新版", Toast.LENGTH_SHORT).show();
                break;
            case R.id.tv_versionName:
                break;
        }
    }

    @Override
    public void onResume() {
        String name = PreferenceUtils.readString(getActivity(), "namefile", "name");
        if (!TextUtils.isEmpty(name)) {
            mBtnLoginNow.setText(name);
            mBtnLoginNow.setEnabled(false);
            mBtnLoginNow.setBackgroundColor(Color.parseColor("#a4d1f9"));
        } else {
            mBtnLoginNow.setText("马上登陆");
            mBtnLoginNow.setEnabled(true);
        }
        super.onResume();
    }
}
